using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine.SceneManagement;

namespace Demo
{

    public class ResourceManager : SingletonBehaviour<ResourceManager>
    {
        public string test="test";
        public static bool IsLocalResource = false;
        private static string writePath = null;

        public static string GetResourceWritePath()
        {
            if (writePath == null)
            {
                if (IsLocalResource)
                {
                    writePath = Application.streamingAssetsPath + "/";
                }
                else
                {
#if !UNITY_EDITOR
                if (Application.platform == RuntimePlatform.WindowsPlayer)
                writePath = Path.Combine(Application.streamingAssetsPath, "WINDOWS/");
                else
                writePath = Application.persistentDataPath + "/Res/en/";
#else
                    writePath = Application.persistentDataPath + "/Res/en/";
#endif
                }
            }
            return writePath;
        }

        public static string GetPlateFormExtension()
        {
#if UNITY_IPHONE
        return "_ios";
#elif UNITY_ANDROID
        return "_and";
#elif UNITY_STANDALONE_WIN
            return "_win";
#elif UNITY_STANDALONE_OSX
        return "_mac";
#elif UNITY_WEBPLAYER
        return "_webgl";
#endif
            return "_webgl";
        }




        public static void FreeAssets()
        {
            Resources.UnloadUnusedAssets();
        }
        public static void FressAssetsNow()
        {
            Resources.UnloadUnusedAssets();
            GC.Collect();
        }

        public static T Load<T>(string path) where T : UnityEngine.Object
        {
            return Resources.Load<T>("Export/" + path);
        }

        public static void LoadLevel(string name)
        {
            EventDispatcher.Instance.DispatchEvent("SceneManager.LoadScene");
            SceneManager.LoadScene(name);
        }
    }
}
